from datetime import datetime
from elasticsearch import Elasticsearch
import pandas as pd

client = Elasticsearch([{'host':'localhost'}])
movies = pd.read_csv("豆瓣250电影基本信息+评论+海报.csv")
movies = movies.fillna("")
for i in range(len(movies)):
    try:
        doc = {}
        doc['movie_name']=movies[i:i+1]['电影名'].values[0]
        doc['movie_info'] = movies[i:i+1]['电影信息'].values[0]
        doc['movie_profile'] = movies[i:i+1]['电影简介'].values[0]
        doc['movie_score'] = movies[i:i+1]['电影评分'].values[0]
        doc['movie_score_amount'] = movies[i:i+1]['评分人数'].values[0]
        doc['movie_short_profile'] = movies[i:i+1]['短简介'].values[0]
        doc['movie_cover'] = movies[i:i+1]['海报url'].values[0]
        doc['movie_comments'] = movies[i:i+1]['电影评论（200条）'].values[0]
        res = client.index(index="douban2.0", id=i, body=doc)
    except Exception as e:
        print(i)
        pass